import React, { useState, useEffect } from 'react'
import { View, Text, } from '@tarojs/components';
import Router from '@/utils/router'
import Taro, { getCurrentInstance, useReachBottom, usePullDownRefresh } from '@tarojs/taro'
import { fetchListUserQaForMessage } from '@/server/shop'
const Qa = (props) => {
    const { QaComponents } = props
    const [page, setPage] = useState({
        limit: 9999,
    })
    const [status, setStatus] = useState('0')
    const [list, setList] = useState([])

    const fetchData = (data) => {
        fetchListUserQaForMessage({
            ...page,
            ...data,
            status
        }).then(val => {
            const { userQaList = [] } = val
            setList(userQaList)
        }).finally(() => {
            Taro.stopPullDownRefresh();
        });
    }
    usePullDownRefresh(() => {
        fetchData()
    })
    const selectList = [
        {
            label: '待支付',
            value: '-1'
        },
        {
            label: '待回复',
            value: '0'
        },
        {
            label: '已回复',
            value: '1'
        },
        {
            label: '待评价',
            value: '3'
        },
        {
            label: '已评价',
            value: '4'
        },]
    useEffect(() => {
        fetchData()
    }, [status])
    return <View>
        <View className="QaComponents_box">

            <View className='QaComponents_select_tab'>
                {selectList.map(item => {
                    const { label, value } = item
                    return <View onClick={() => {
                        if (status !== value) {
                            setStatus(value)
                        }
                    }} className={`QaComponents_select_item ${value === status ? 'QaComponents_select_itemSelect' : ''}`}>
                        {label}
                    </View>
                })}


            </View>
        </View>
        {list.map((item, index) => {
            return <QaComponents data={item} key={index}></QaComponents>
        })}
    </View>
}
export default Qa
